package models

import "gvb_server/models/ctype"

type UserModel struct {
	Model
	NickName       string           `gorm:"type:varchar(20);not null;unique;comment:昵称"`
	Username       string           `gorm:"type:varchar(20);not null;unique;comment:用户名"`
	Password       string           `gorm:"type:varchar(255);not null;comment:密码"`
	Avatar         string           `gorm:"type:varchar(255);not null;comment:头像"`
	Email          string           `gorm:"type:varchar(255);not null;unique;comment:邮箱"`
	Phone          string           `gorm:"type:varchar(20);not null;unique;comment:手机号"`
	Role           ctype.Role       `gorm:"type:int(11);not null"`
	SignState      ctype.SignStatus `gorm:"type:int(11);not null"`
	CollectsModels []ArticleModel   `gorm:"many2many:user_collect_models;joinForeignKey:UserID;JoinReferences:ArticleID" json:"_"` // 收藏的文章列表
}

func ParseRole(role ctype.Role) string {
	switch role {
	case ctype.PermissionAdmin:
		return "管理员"
	case ctype.PermissionUser:
		return "用户"
	case ctype.PermissionGuest:
		return "游客"
	case ctype.PermissionDisabled:
		return "禁用"
	default:
		return "未知"
	}
}
